HEADERS_PATH = ${shell find ./include -type d|sed 's/^/-I/'}
C_SOURCES = ${shell find -name *.c}  
# C_SOURCES = $(wildcard kernel/*.c drivers/*.c)
HEADERS = $(wildcard include/*.h include/video/*.h)


OBJ = ${C_SOURCES:.c=.o}
CC = gcc
LD = ld

all : os-image

run : all
	qemu os-image

os-image : boot/boot_sect.bin kernel.bin boot/padding.bin 
	cat $^ > os-image

kernel.bin : kernel/kernel_entry.o ${OBJ}
	$(LD) -o $@ -Ttext 0x1000 $^ --oformat binary

kernel/kernel_entry.o : kernel/kernel_entry.asm
	nasm $< -f elf -o $@

%.o : %.c
	$(CC) -ffreestanding ${HEADERS_PATH} -c $< -o $@ -std=gnu99 -O2 -Wall -Wextra

%.o : %.asm 
	nasm $< -f elf -o $@

%.bin : %.asm
	nasm $< -f bin -I 	'boot/16bit/' -I 'boot/32bit/' -I 'boot/' -o $@

boot/padding.bin : boot/padding.asm
	nasm $< -o $@

clean : 
	rm -fr *.bin *.o *.dis os-image
	rm -fr kernel/*.o boot/*.bin drivers/*.o
